home *** CD-ROM | disk | FTP | other *** search
- On Sunday 15-Mar-98 at 23:35:14, a nutter named Jonas Thorell
- had wet pants when they typed about `Textfile parsing'.
- >Okay, see if someone can help me out here. What I want is to take an
- >ordinary textfile and process in certain ways.
-
- >1. Determine how many lines of text it is in it. How?
- >2. Use the above value making a for-loop like
-
- >For a=1 to <the value mentioned>
- >grab one line of text and insert it in t$(a)
-
-
- Hiya Jonas,
-
- Here is a nice bit of code which I have been using for a long long
- time in many disk mag coded productions (eg. DMC, BTF etc).
-
- Simply cut this out and use the Merge ASCII option to load it into
- Amos to fiddle about with it...enjoy.
-
-
- <SNIP HERE>
- '
- ' ***************************************
- '
- ' Load and process a text file easily :)
- ' bY Andy Gibson
- '
- ' I hope this helps you out Jonas....
- '
- ' ***************************************
- '
- ' Depending on the size of your file, you may need to UP this value...
- Set Buffer 40
- '
- ' LINES must be global here...
- Global TXT$,LINES
- '
- ' Enter your text file's full path here...
- Proc _LOAD_TXT["dev:dir/file"]
- '
- '
- ' Now we can use a Dim with the correct amount of lines to hold
- ' each line in there...
- Dim TXT$(LINES)
- Global TXT$()
- '
- ' Simply sort the lines into the Global Dim here...
- Proc _SORT_FILE
- '
- '
- ' Now you can easily read any line of the text held in the array
- ' TXT$().
- '
- '
- ' Procedure are here...
- '
- Procedure _LOAD_TXT[TXT$]
- '
- ' This Proc will work out how many lines are in your file.
- ' Checks for normal Chr$(10) RETURN code. You could alter
- ' it to Chr$(13) for PC text files if need be....
- '
- ' Amcaf only.... (no need to use Open in etc...)
- ' Dload TXT$,17
- '
- '
- ' Amos normal way...
- Open In 1,TXT$
- L=Lof(1) : Close 1
- Reserve As Data 7,L
- Bload CF$,7
- '
- '
- ' Read Lines...
- POS=Start(7) : LINES=0
- '
- Do
- Exit If POS>=Bank End(7)
- LINES1=Hunt(POS To Bank End(7),Chr$(10))
- '
- ' Wanna see the text...
- A$=Peek$(POS,POS-LINE,Chr$(10))
- Print A$
- '
- Exit If LINE=Bank End(7) or LINE=0
- POS=LINE+1
- Inc LINES
- Loop
- '
- ' One other point to note, the Bank End command is not an normal
- ' Amos Pro one! And I can't remember which Ext I have installed
- ' which uses it! If this code doesn't funtion properly in your
- ' interpreter, simply change the Bank End commands to summat
- ' more suitable like Start(bnk)+start(bnk) to Length(bnk)
- '
- End Proc
- Procedure _SORT_FILE
- '
- ' Hold each line of text in the array...easy or what?
- '
- POS=Start(7)
- '
- For I=0 To LINES
- A$=Peek$(POS,Bank End(7),Chr$(10))
- If A$>""
- TXT$(I)=Peek$(POS,Bank End(7),Chr$(10))
- Add POS,Len(TXT$(I))+1
- Else
- Inc POS
- End If
- Next I
- '
- ' No more need to hold the file in a mem bank, so erase it...
- '
- Erase 7
- '
- End Proc
-
-
- <SNIP>
-
- Onbiosuly you could also do more to this such as adding pages and the
- likes, but I'll leave you to easily work that one out :)
-
- Tarra for now....Andy Gibson
-
- --
- *****************************************************************
- *_______/\_____/\_______/\_____/\ *
- *\ /\ ___/\ /\ ___/ Andy Gibson <---------------- *
- * \_/\ / /\/| _ \_/\ / \/ \ ----------> aka SKiDZ/Area 51 *
- * / _/ / / |_| // _/ / __\ \ *
- * \// / \___ / \// / /__ / andy@agasinc.demon.co.uk *
- * /_/ \_/ /_/ \_/ <-=-=-=-=-=-=-=-=-=-> *
- * pRODUCTiONS 9T8 *
- *****************************************************************
-
-
-
-